package com.gaoda.booksystem.sysService.impl;

import com.gaoda.booksystem.entity.Book;
import com.gaoda.booksystem.mapper.SysBookMapper;
import com.gaoda.booksystem.sysService.SysBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysBookServiceImpl implements SysBookService {

    @Autowired
    SysBookMapper sysBookMapper;

    //根据书的编号查找书籍
    @Override
    public Book findByBookNum(int bookNumber) {
        return sysBookMapper.findByBookNum(bookNumber);
    }

    //模糊查询 + 分页
    @Override
    public List<Book> queryBooks(String bookName, String bookPublishers, String bookType, int currentPage, int pageCount) {
        return sysBookMapper.queryBooks(bookName, bookPublishers, bookType, (currentPage - 1) * pageCount,pageCount*currentPage);
    }

    //获得总页数
    @Override
    public int getTotalPage(int pageCount, String bookName, String bookPublishers, String bookType) {
        Integer total = sysBookMapper.getTotalPage(bookName, bookPublishers, bookType);
        return (total - 1) / pageCount + 1;
    }

    //删除书籍
    @Override
    public int deleteBookByBookNum(int bookNumber) {
        return sysBookMapper.deleteBookByBookNum(bookNumber);
    }

    //添加书籍
    @Override
    public int addBook(Book book) {
        return sysBookMapper.addBook(book);
    }

    //修改书籍信息
    @Override
    public int updateBook(Book book) {
        return sysBookMapper.updateBook(book);
    }

    @Override
    public int findBookId() {
        return sysBookMapper.findBookId();
    }

    @Override
    public List<Book> bookList() {
        return sysBookMapper.bookList();
    }
}
